package com.androidhive.jsonparsing;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.util.Log;

public class JavascriptInterface {
	Context context;

	public JavascriptInterface(QuickActionMessage quickActionMeaasage) {
	//	this.context = quickActionMeaasage;
	}
	
	public JavascriptInterface(QuickActionChange quickActionChange) {
	//	this.context = quickActionMeaasage;
	}

	public JavascriptInterface(QuickAction quickAction) {
		// TODO Auto-generated constructor stub
	}

	public void Call(String numberP) {
		Intent callIntent = new Intent(Intent.ACTION_CALL);
		callIntent.setData(Uri.parse("tel:" + numberP));
		context.startActivity(callIntent);
	}

	public void SentMS(String numberP) {

	}
	
//	public void TestLink(String url)
//	{
//		ActivityInfomations.callWV("http://sina.vn");
//		Log.d("log", "okkkkkkkkkkkkkkkkkk");
//	}

	int count = 0;

	public void showNotification(String message, String url) {
		Log.i("Callfunction -> showNotifice() --", message);
		NotificationManager mManager = (NotificationManager) context
				.getSystemService(Context.NOTIFICATION_SERVICE);
		Notification notification = new Notification(R.drawable.ic_launcher,
				message, System.currentTimeMillis());

		Intent notificationIntent = new Intent(context, com.androidhive.jsonparsing.Activity_ChatIndex.class);
		notificationIntent.putExtra("url", url);

		PendingIntent contentIntent = PendingIntent.getActivity(context, 0,
				notificationIntent, 0);

		notification.setLatestEventInfo(context, "Vatgia.com",
				message, contentIntent);

		mManager.notify(count, notification);
		count++;
		Log.i("call function", "click");
	}

	public void SetData(String key, String value)
	{
		Log.i("JavascriptInterface -> SetData()",key);
		FileOutputStream fos = null;
		try {
			fos = context.openFileOutput(key, Context.MODE_PRIVATE);
			fos.write(value.getBytes());
			fos.close();
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
			
	}
	
	public String GetData(String key)
	{
		Log.i("JavascriptInterface -> GetData()",key);
		FileInputStream fis = null;
		String _return = null;
		try {
			fis = context.openFileInput(key);
			byte[] data = null;
			fis.read(data);
			fis.close();
			_return = String.valueOf(data);
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return _return;
	}
	
	public void DeleteData(String key)
	{
		Log.i("JavascriptInterface -> DeleteData()",key);
		File f = null;
		f = context.getFileStreamPath(key);
		if(f != null)
		{
			f.delete();
		}
	}
}
